<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/13 0013
 * Time: 下午 2:03
 */

namespace app\admin\model;


use app\common\model\BaseModel;
use think\Log;
use think\Model;
use app\common\service\MiniProgramHelp;

class Tenant extends BaseModel {

    /**
     * @param $tenantId
     */

    public function findTenantDetail($tenantId){
        return self::where('id','=',$tenantId)->find();
    }

    /**
     * 修改审核状态
     * @param $businessMiniProgramStatus
     * @param \backend\models\BusinessMiniProgram $businessMiniProgram
     * @author fei <xliang.fei@gmail.com>
     */
    public static function updateStatusByAuditStatus($businessMiniProgramStatus, $businessMiniProgram)
    {

        if (isset($businessMiniProgramStatus['errcode']) && $businessMiniProgramStatus['errcode'] == 0) {
            switch ($businessMiniProgramStatus['status']) {
                //审核成功
                case 0:
                    $businessMiniProgram->wxStatus = 4;
                    $businessMiniProgram->save();

                    //发布代码
                    MiniProgramHelp::releaseCode($businessMiniProgram->id);
                    break;
                //审核失败
                case 1:
                    $businessMiniProgram->wxStatus = 3;
                    $businessMiniProgram->auditMsg = $businessMiniProgramStatus['reason'];
                    $businessMiniProgram->save();
                    break;
                //审核中
                default:
                    break;
            }
        }
    }

    public function getTenant($tenantId){
        return self::where('id','=',$tenantId)->find();
    }

}